


import axios from 'axios'


export default function request(config) {
  const instance = axios.create({
    baseURL: 'http://123.207.32.32:8000',
    timeout: 5000
  });

  //请求拦截器
  instance.interceptors.request.use(config=>{
    return config
  }, err =>{
    console.log('instance request error=', err)
  })

  //响应拦截器
  instance.interceptors.response.use(response=>{
    return response.data
  },(err=>{
    console.log('来到了response拦截failure中\n', err);
    if (err && err.response) {
      switch (err.response.status) {
        case 400:
          err.message = '请求错误'
          break
        case 401:
          err.message = '未授权的访问'
          break
      }
    }
    return err
  }))

  return instance(config)
}